package com.eece496.Database;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Attendance extends Database{

	private String COGSName;
	private int studentID;
	private String sectionNumber;
	private String courseNumber;
	private String status;
	private int id=0;
	
	public Attendance()
	{
		tableName = "Attendance";
	}
	
	public Attendance(int studentID, String COGSName, String status, String courseNumber, String sectionNumber)
	{
		tableName = "Attendance";
		this.studentID = studentID;
		this.COGSName = COGSName;
		this.status = status;
		this.courseNumber = courseNumber;
		this.sectionNumber = sectionNumber;
	}
	
	@Override
	public void Insert() throws SQLException {
		
		Statement stmt = connection.createStatement();
		
	    String sqlString = "INSERT INTO " + tableName + " VALUES (" + id + ", " + 
	    					studentID + ", " +
	    					AddQuotes(COGSName) + ", " +
	    					AddQuotes(status) + ", " + 
	    					AddQuotes(courseNumber) + ", " +
	    					AddQuotes(sectionNumber)+
	    					")";
	    
	    stmt.executeUpdate(sqlString);
	        
	    System.out.println(sqlString + " complete");		
	}

	public void DeleteFromCourseSection(String courseNumber, String sectionNumber) throws SQLException
	{
		Statement stmt = connection.createStatement();
		String sqlString = "DELETE from " + tableName + " WHERE courseNumber = " +AddQuotes(courseNumber) + " and sectionNumber = " + 
		AddQuotes(sectionNumber);
		stmt.executeUpdate(sqlString);
		System.out.println(sqlString + " complete");
	}
	
	public String getStatus(int studentID, String COGSName, String courseNumber, String sectionNumber) throws SQLException
	{
		Statement stmt = connection.createStatement();
		String sqlString = "SELECT status FROM " + tableName + " where studentID = " + studentID + " and COGSName = " + 
		AddQuotes(COGSName) + " and courseNumber = " + AddQuotes(courseNumber) +  " and sectionNumber = " + AddQuotes(sectionNumber);
		String status = null;
	    ResultSet rs = stmt.executeQuery(sqlString);
	    while(rs.next())
	    {
	    	status = rs.getString("status");
	    	
	    }
	    
	    return status;
	}
	
	@Override
	public void Delete(String primaryKey) throws SQLException {
		// TODO Auto-generated method stub
	}

	@Override
	public void Display() throws SQLException {
		// TODO Auto-generated method stub
	}
}
